<?php
set_include_path('system'.PATH_SEPARATOR.'templates');

require_once('Template.php');
require_once('RedirectBrowserException.php');
require_once('DatabaseUtility.php');

$tmpl = new Template();

$filter = empty($_GET['fil'])? '' : $_GET['fil'];
$org = empty($_GET['org'])? '' : $_GET['org'];
$ref = empty($_GET['ref'])? '' : $_GET['ref'];
$acc = empty($_GET['acc'])? '' : $_GET['acc'];
$desc = empty($_GET['desc'])? '' : $_GET['desc'];

openDatabase();
$tmpl->organismSelect = getOrganismSelect();
$tmpl->dataSourceSelect = getDataSourceSelect();

$where = "";
$get = "";
if (strlen($acc)!=0) {
        $acc = strtolower($acc);
        $where = "(id IN (SELECT p3dbId FROM idMapping WHERE lower(otherId) LIKE '%$acc%'))";
        $get = "acc=$acc";
}
if (strlen($desc)!=0) {
        $desc = strtolower($desc);
        $where = $where." AND ";
        $get = $get."&";
    $where = $where."lower(annotation) LIKE '%$desc%'";
    $get = $get."desc=$desc";
}
if (!empty($ref)) { // some specific ref was selected
        $where = $where." AND ";
        $get = $get."&";
    $where = $where."EXISTS (SELECT * from proteinDataSourceRelation WHERE proteinDataSourceRelation.protein=protein.id AND proteinDataSourceRelation.datasource='$ref')";
    $get = $get."ref=$ref";
}
closeDatabase();

$tmpl->current = 'search';
$tmpl->pageContent = $tmpl->build('search.tmpl');

print $tmpl->build('page.tmpl');
?>